package tech.aistar.corejava.day10.stringextends;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:拓展...
 * @date 2019/7/26 0026
 */
public class StringCompareDemo {
    public static void main(String[] args) {
        String s2 = "abc";
        //创建了几个对象 - 1个或者2个
        String s1 = new String("abc");//s1指向的是堆,非串池里的"abc"

        String s3 = "a"+"b"+"c";//创建了几个对象 "a" "b"  "ab"  "c" "abc" -> 5个

        //拓展比较

        System.out.println(s2 == s1);

        //在串池 - 常量池
        //String x1 = "a";//※

        //final修饰的字符串,肯定在编译期间,JVM肯定会放在常量池.
        final String x1 = "a";////※

        //当x1如果被final修饰,那么x1+"b" - JVM在编译期间,在底层就会把这句话优化成"a"+"b";
        String x2 = x1 + "b";

        String x4 = "a" + "b";////※  最明显的,"a"  "b" "ab" 都在常量池

        String x3 = "ab";
        System.out.println(x3 == x2);//false
        System.out.println(x3 == x4);//true
    }

}
